/*     */ package com.alipaydb.util;
/*     */ 
/*     */ import com.alipaydb.config.AlipayConfig;
/*     */ import com.alipaydb.util.httpClient.HttpProtocolHandler;
/*     */ import com.alipaydb.util.httpClient.HttpRequest;
/*     */ import com.alipaydb.util.httpClient.HttpResponse;
/*     */ import com.alipaydb.util.httpClient.HttpResultType;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import org.apache.commons.httpclient.NameValuePair;
/*     */ 
/*     */ public class AlipaySubmit
/*     */ {
/*     */   private static Map<String, String> buildRequestPara(Map<String, String> sParaTemp)
/*     */   {
/*  35 */     Map sPara = AlipayCore.paraFilter(sParaTemp);
/*     */ 
/*  37 */     String mysign = AlipayCore.buildMysign(sPara);
/*     */ 
/*  40 */     sPara.put("sign", mysign);
/*  41 */     sPara.put("sign_type", AlipayConfig.sign_type);
/*     */ 
/*  43 */     return sPara;
/*     */   }
/*     */ 
/*     */   public static String buildForm(Map<String, String> sParaTemp, String gateway, String strMethod, String strButtonName)
/*     */   {
/*  57 */     Map sPara = buildRequestPara(sParaTemp);
/*  58 */     List keys = new ArrayList(sPara.keySet());
/*     */ 
/*  60 */     StringBuffer sbHtml = new StringBuffer();
/*     */ 
/*  62 */     sbHtml.append("<form id=\"alipaysubmit\" name=\"alipaysubmit\" action=\"" + gateway + "_input_charset=" + AlipayConfig.input_charset + "\" method=\"" + strMethod + "\">");
/*     */ 
/*  66 */     for (int i = 0; i < keys.size(); i++) {
/*  67 */       String name = (String)keys.get(i);
/*  68 */       String value = (String)sPara.get(name);
/*     */ 
/*  70 */       sbHtml.append("<input type=\"hidden\" name=\"" + name + "\" value=\"" + value + "\"/>");
/*     */     }
/*     */ 
/*  74 */     sbHtml.append("<input type=\"submit\" value=\"" + strButtonName + "\" style=\"display:none;\"></form>");
/*  75 */     sbHtml.append("<script>document.forms['alipaysubmit'].submit();</script>");
/*     */ 
/*  77 */     return sbHtml.toString();
/*     */   }
/*     */ 
/*     */   private static NameValuePair[] generatNameValuePair(Map<String, String> properties)
/*     */   {
/*  86 */     NameValuePair[] nameValuePair = new NameValuePair[properties.size()];
/*  87 */     int i = 0;
/*  88 */     for (Map.Entry entry : properties.entrySet()) {
/*  89 */       nameValuePair[(i++)] = new NameValuePair((String)entry.getKey(), (String)entry.getValue());
/*     */     }
/*     */ 
/*  92 */     return nameValuePair;
/*     */   }
/*     */ 
/*     */   public static String sendPostInfo(Map<String, String> sParaTemp, String gateway)
/*     */     throws Exception
/*     */   {
/* 105 */     Map sPara = buildRequestPara(sParaTemp);
/*     */ 
/* 107 */     HttpProtocolHandler httpProtocolHandler = HttpProtocolHandler.getInstance();
/*     */ 
/* 109 */     HttpRequest request = new HttpRequest(HttpResultType.BYTES);
/*     */ 
/* 111 */     request.setCharset(AlipayConfig.input_charset);
/*     */ 
/* 113 */     request.setParameters(generatNameValuePair(sPara));
/* 114 */     request.setUrl(gateway + "_input_charset=" + AlipayConfig.input_charset);
/*     */ 
/* 116 */     HttpResponse response = httpProtocolHandler.execute(request);
/* 117 */     if (response == null) {
/* 118 */       return null;
/*     */     }
/*     */ 
/* 121 */     String strResult = response.getStringResult();
/*     */ 
/* 123 */     return strResult;
/*     */   }
/*     */ }

/* Location:           F:\电商\commons-utils.jar
 * Qualified Name:     com.alipaydb.util.AlipaySubmit
 * JD-Core Version:    0.6.0
 */